﻿
CREATE PROCEDURE [dbo].[proc_Order_AdminUpdate_new] 
(
		@OId uniqueidentifier
		,@CId int
		,@CusPerson	nvarchar(50)
		,@CusPersonTel nvarchar(50)
		,@CusDescription nvarchar(1000)
		,@CusEstimate nvarchar(200)
		,@WayId	int
		,@WayName nvarchar(50)
		,@ProcessId	int
		,@ProcessName nvarchar(50)
		,@TradeDate	datetime
		,@shjbh	nvarchar(50)
		,@htbh nvarchar(50)
		,@Discount nvarchar(50)
		,@PaymentTypeId	int
		,@PaymentType nvarchar(50)
		,@BankId int
		,@Bank nvarchar(50)
		,@PaymentDescription nvarchar(200)
		,@OtherDescription nvarchar(1000)
	)
AS
Begin
	Insert Into Order_Before([Id],[OId],[CusPerson],[CusPersonTel],[CusDescription],[CusEstimate]
		,[WayId],[WayName],[ProcessId],[ProcessName],[TradeDate],[Discount],[PaymentTypeId]
		,[PaymentType],[BankId],[Bank],[PaymentDescription],[OtherDescription],[shjbh],[htbh])
	Select [Id],[OId],[CusPerson],[CusPersonTel],[CusDescription],[CusEstimate]
		,[WayId],[WayName],[ProcessId],[ProcessName],[TradeDate],[Discount],[PaymentTypeId]
		,[PaymentType],[BankId],[Bank],[PaymentDescription],[OtherDescription],[shjbh],[htbh]
	From [Order] Where OId=@OId

	Update [Order] Set
			CusPerson=@CusPerson
			,CusPersonTel=@CusPersonTel
			,CusDescription=@CusDescription
			,CusEstimate=@CusEstimate
			,WayId=@WayId
			,WayName=@WayName
			,ProcessId=@ProcessId
			,ProcessName=@ProcessName
			,TradeDate=@TradeDate
			,shjbh=@shjbh
			,htbh=@htbh
			,Discount=@Discount
			,PaymentTypeId=@PaymentTypeId
			,PaymentType=@PaymentType
			,BankId=@BankId
			,Bank=@Bank
			,PaymentDescription=@PaymentDescription
			,OtherDescription=@OtherDescription
		Where OId=@OId
	Update [Order_Change] Set flag=1 Where OId=@OId And Id=@CId And flag=0
End